home *** CD-ROM | disk | FTP | other *** search
-
- ******************************************************************************
- * *
- * HodgePodge: An example Apple IIGS Desktop application *
- * *
- * Written in 65816 Assembler by the Apple IIGS Tools Team *
- * Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS" *
- * *
- * Copyright (c) 1986-87 by Apple Computer, Inc. *
- * *
- * ---------------------------------------------------------------------- *
- * *
- * ASM65816 Code file "INIT.ASM" -- Toolbox startup/shutdown routines *
- * *
- ******************************************************************************
-
-
-
- *****************************************************************
- *
- * INIT.ASM
- *
- * Contains the following global data
- *
- * MyID Variable holding userid of this program
- *
- * ThisMode Variable holding mode used to start
- * QuickDraw
- * OrigPort Variable holding pointer to original
- * port that QuickDraw has when started up.
- *
- * Contains the following private data
- *
- * ZPHandle Holds handle to memory that is used
- * as direct page for the tools.
- * ZPPtr Pointer to above memory.
- *
- * Contains the following public procedures.
- *
- * function StartupTools (ModeToUse : SCB_type) : integer;
- *
- * Starts up the tools (initializing quickdraw with the specified
- * mode) and initializes the global variables above.
- *
- * procedure ShutdownTools;
- * Shuts things down, undoing what was done above.
- *
- * Uses the MountBootDisk dialog routine to have the user put the
- * system disk on line.
- *
- * Uses the CheckToolError dialog routine to cause a system death
- * (bouncing apple) if the A register is nonzero. The X register is
- * assumed to contain a "Where" value.
- *
- * Change History
- *
- * June 1987 Steven E. Glass
- * August 1987 Ben Koning
- *
- * Modified to use the C calling convention so that can be used by
- * both C and TMLPascal. (Input parameters are not removed from
- * the stack.)
- *
- *****************************************************************
-
-
- InitDummy START
-
- COPY 7/E16.MEMORY
-
- END
-
- ****************************************************************
- *
- * StartupTools
- *
- * Input: ModeToUse -- $0080 for 640 mode
- * Output: ErrorCode -- Error if nonzero
- * (NOTE: DIFFERENT FROM C AND PASCAL VERSIONS)
- *
- * Calling Sequence:
- *
- * pha ; space for output
- * PushWord #Mode ; Mode to use for QD
- * jsl StartupTools
- * plx ; remove input parameter
- * pla ; get func result
- * bne MustQuit
- *
- * This is a subroutine to load and startup all the tools
- * an application generally needs. This routine also gets the
- * space in bank zero that the tools use for direct page. The
- * only time an error code other than zero is returned is when
- * the boot disk is not on line and the user asks to cancel
- * rather than to put it on line.
- *
- * Order of work:
- *
- * 1) Start
- *
- * Tool Locator, Memory Manager, Misc Tools
- * QuickDraw, Event Manager
- *
- * 2) When these are running, the "One moment please" string is
- * displayed and LoadTools is called.
- *
- * QuickDraw and the Event Manager are started up first
- * because if the LoadTools call returns a VolNotFound error
- * we need to have the volume mounted. This is done with
- * the TLMountVolume call which requires both QuickDraw and
- * the Event Manager to be active.
- *
- * 3) Next I start up
- *
- * Window Manager, Control Manager,
- * Menu Manager, LineEdit, Dialog Manager
- *
- * 4) After these are initialized, I setup and draw the
- * menu bar and display a message to the user before I
- * initialize the rest (Standard File, Font Manager,
- * QuickDraw Auxiliary and print manager).
- *
- ****************************************************************
- StartupTools START
- using InitData
-
- ModeToUse equ $5
- ResultCode equ $7
-
- ;-----------------------------------------------
- ;
- ; Direct Page use. The following equates
- ; describe how the direct pages are assigned
- ; to the tools below.
- ;
- DPForQuickDraw equ $000 ; needs 3
- DPForEventMgr equ $300 ; needs 1
- DPForCtlMgr equ $400 ; needs 1
- DPForLineEdit equ $500 ; needs 1
- DPForMenuMgr equ $600 ; needs 1
- DPForStdFile equ $700 ; needs 1
- DPForFontMgr equ $800 ; needs 1
- DPForPrintMgr equ $900 ; needs 2
-
- TotalDP equ $B00
-
- ;-----------------------------------------------
- ;
- ; Just in case this routine is called when the
- ; data bank is set somewhere else we set it
- ; right here.
- ;
- phb
- phk
- plb
-
- ;-----------------------------------------------
- ;
- ; Copy the input parameter into the global
- ; data area and initialize the result code
- ; assuming all is well.
- ;
- lda ModeToUse,s
- sta ThisMode
-
- lda #0
- sta ResultCode,s
-
- ;-----------------------------------------------
- ;
- ; Start with TLStartup
- ;
- _TLStartup ; Tool Locator
-
-
- ;-------------------------------------------------
- ;
- ; Initialize the memory manager.
- ;
-
- PushWord #0
- _MMStartup
- ldx #1
- jsr CheckToolError
-
- pla
- sta MyID
-
- ;-------------------------------------------------
- ;
- ; Initialize misc tools.
- ;
- _MTStartup
- ldx #2
- jsr CheckToolError
-
-
- ;------------------------------------------------------
- ;
- ; First get some memory for the zero page we need!
- ;
- pha ; space for handle
- pha
- PushLong #TotalDP
- PushWord MyID
- PushWord #attrBank+attrPage+attrFixed+attrLocked
- PushLong #0
- _NewHandle
-
- ldx #3
- jsr CheckToolError
-
-
- ;-------------------------------------------------
- ;
- ; Take the resulting handle (still on the stack)
- ; and dereference it, putting the pointer into
- ; ZPPtr.
- ;
- phd ; save current D
- tsc ; turn stack into direct page
- tcd
- lda [3] ; deref the pointer
- sta ZPPtr ; we know that high word is 0
- pld ; restore direct page
-
- pla ; put handle into storage
- sta ZPHandle
- pla
- sta ZPHandle+2
-
- ;-------------------------------------------------------------
- ;
- ; Note that width on startup is 320 to allow doubling the
- ; screen width when doing best printing.
- ;
-
- lda ZPPtr
- clc
- adc #DPForQuickDraw
- pha
- PushWord ThisMode
- PushWord #320 ; max size of scan line in bytes
- PushWord MyID
- _QDStartup
-
- ldx #4
- jsr CheckToolError
-
- PushLong #0
- _GetPort
- PullLong OrigPort
-
- ldy #640
- lda ThisMode
- cmp #$80
- beq okmode
- ldy #320
- okmode anop
- sty MaxX
-
- lda ZPPtr
- clc
- adc #DPForEventMgr
- pha
- PushWord #20 ; queue size
- PushWord #0 ; x clamp low
- PushWord MaxX ; x clamp high
- PushWord #0 ; y clamp low
- PushWord #200 ; y clamp high
- PushWord MyID
- _EMStartup
-
- ldx #5
- jsr CheckToolError
-
- ;-------------------------------------------------------
- ;
- ; Put up a string telling user that something is
- ; happening.
- ;
- PushWord #20
- PushWord #20
- _MoveTo
-
- PushWord #0
- _SetBackColor
-
- PushWord #$F
- _SetForeColor
-
- PushLong #MomentStr
- _DrawString
-
- _ShowCursor
-
-
- ;-------------------------------------------------------
- ;
- ; Make the LoadTools call
- ;
- LoadAgain _GET_FILE_INFO ParamBlock ;Try to find the directory
- bcc OkToLoad ;*/SYSTEM/TOOLS/. Ok? Go load.
-
- jsr MountBootDisk ;Else, display psuedo-dialog
- cmp #1 ;Did they select "OK"?
- beq LoadAgain ;Yes, so try it again.
-
- ; ;Else, they selected "Cancel".
- sta ResultCode,s ;So return result code
- brl GetOut ;and leave this routine.
-
- OkToLoad PushLong #ToolTable ;Push address of tool table
- _LoadTools ;Attempt to load them (should
- bcc ToolsLoaded ;work). If ok, go on.
-
- ldx #6 ;If error happened anyway,
- jsr CheckToolError ;we'll just die here.
-
- ;------------------------------------------------------
- ;
- ; The tools are loaded so start them up.
- ;
- ToolsLoaded anop
- _QDAuxStartup ; QuickDraw Auxiliary
-
- _WaitCursor ; With QDAux started we can show the
- ; ; watch cursor
-
- PushWord MyID ; Window Manager
- _WindStartup
-
- ldx #7
- jsr CheckToolError
-
- PushLong #$0000 ; display desktop
- _RefreshDeskTop
-
- PushWord MyID ; Control Manager
- lda ZPPtr
- clc
- adc #DPForCtlMgr
- pha
- _CtlStartup
-
- ldx #8
- jsr CheckToolError
-
- PushWord MyID ; LineEdit
- lda ZPPtr
- clc
- adc #DPForLineEdit
- pha
- _LEStartup
-
- ldx #9
- jsr CheckToolError
-
- PushWord MyID ; Dialog Manager
- _DialogStartup
-
- ldx #10
- jsr CheckToolError
-
- PushWord MyID ; Menu Manager
- lda ZPPtr
- clc
- adc #DPForMenuMgr
- pha
- _MenuStartup
-
- ldx #11
- jsr CheckToolError
-
- _DeskStartup ; Desk Manager
-
- jsr ShowPleaseWait ; Message for user
-
- ldx #12
- jsr CheckToolError
-
- PushWord MyID ; Standard File
- lda ZPPtr
- clc
- adc #DPForStdFile
- pha
- _SFStartup
-
- ldx #13
- jsr CheckToolError
-
- PushWord #$8000 ; display file names in all caps
- _SFAllCaps
-
- PushWord MyID ; Print Manager
- lda ZPPtr
- clc
- adc #DPForPrintMgr
- pha
- _PMStartup
-
- ldx #14
- jsr CheckToolError
-
- PushWord MyID ; Font Manager
- lda ZPPtr
- clc
- adc #DPForFontMgr
- pha
- _FMStartup
-
- ldx #15
- jsr CheckToolError
-
- jsr HidePleaseWait
-
- _InitCursor ; reset cursor to arrow cursor
-
-
- ;-------------------------------------------------------
- ;
- ; All is done. We must clean up the stack and get out
- ;
- GetOut anop
- plb ; restore dbr
- rtl ; all done.
-
- MomentStr str 'One moment please...'
-
- MaxX ds 2
-
- ParamBlock dc i4'PathName' ;ProDOS/16 Parameter block
- ds 2 ;With pathname as input; rest of the
- ds 2 ;fields will be set as output.
- ds 4
- ds 2
- ds 2
- ds 2
- ds 2
- ds 2
- ds 4
- PathName str '*/SYSTEM/TOOLS'
-
- END
-
-
- *****************************************************************
- *
- * PublicInitData
- *
- * These are global variables available to the main program.
- *
- *****************************************************************
-
- PublicInitDATA DATA ~Global
-
- ;------------------------------------------------
- ;
- ; Public Variables
- ;
-
- MyID ENTRY
- ds 2
-
- ThisMode ENTRY
- ds 2
-
- OrigPort ENTRY
- ds 2
-
- END
-
-
- InitData PrivDATA
-
- ZPHandle ds 4
-
- ZPPtr ds 4
-
- ToolTable anop
- StartTable anop
- dc i'(EndTable-StartTable)/4'
- dc i'1,$0101' ; tool locator
- dc i'2,$0101' ; memory manager
- dc i'3,$0101' ; misc tools
- dc i'4,$0101' ; quickdraw
- dc i'5,$0100' ; desk manager
- dc i'6,$0100' ; event manager
- dc i'14,$0103' ; window manager
- dc i'15,$0103' ; menu manager
- dc i'16,$0103' ; control manager
- dc i'18,$0100' ; quickdraw aux
- dc i'19,$0100' ; print manager
- dc i'20,$0100' ; line edit
- dc i'21,$0100' ; dialog manager
- dc i'22,$0102' ; scrap manager
- dc i'23,$0100' ; standard file
- dc i'27,$0100' ; Font manager
- dc i'28,$0100' ; List manager
- EndTable anop
- END
-
-
-
- ****************************************************************
- *
- * ShutDownTools
- *
- * Inputs: None
- *
- * Outputs: None
- *
- *
- * Shuts down every thing started up in InitTools
- *
- ****************************************************************
-
- ShutDownTools START
- using InitData
-
-
- _DeskShutdown ; shut this first so that other tools
- ; ; are still around (close DA's)
- _FMShutDown
- _PMShutdown
- _SFShutDown
- _DialogShutdown
- _LEShutdown
- _MenuShutDown
- _WindShutDown
- _CtlShutdown ; this is shut down after window mgr
- ; ; because window mgr makes contol
- ; ; manager calls at shutdown time.
-
- _EMShutDown
- _QDAuxShutdown
- _QDShutDown
- _MTShutdown
-
- PushLong ZPHandle ; get rid of handle for direct
- _DisposeHandle ; page
-
- PushWord MyID
- _MMShutdown
-
- _TLShutdown
-
- rtl
-
- END
-